/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sgs.dao;

import br.com.sgs.entity.Status;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Eric
 */
public class DAOStatus extends AbstractDAO implements IDAOStatus{
    
    public DAOStatus(){
        super();
    }
    
    @Override
    public Status findStatusById(int idstatus) {
         try {

            Query q = em.createQuery("SELECT s FROM Status s WHERE s.id = :idstatus");
            q.setParameter("idstatus", idstatus);
            return (Status) q.getSingleResult();

        } catch (Exception e) {
            System.err.println("Erro no findStatusById");
            return null;
        }
    }

    @Override
    public List<Status> findStatus() {
        try {

            Query q = em.createQuery("SELECT s FROM Status s");
            return q.getResultList();

        } catch (Exception e) {
            System.err.println("Erro no findStatus");
            e.printStackTrace();
            return null;
        }
    }
    
    @Override
    public List<Status> findStatusByDescricao(String descricao) {
        try {

            Query q = em.createQuery("SELECT s FROM Status s WHERE UPPER(s.descricao) LIKE :descricao");
            q.setParameter("descricao", "%"+descricao+"%");
            
            return q.getResultList();

        } catch (Exception e) {
            System.err.println("Erro no findModeloByDescricao");
            e.printStackTrace();
            return null;
        }
    }
    
}
